<?php
/**
 * @author     ：lhw
 * @date       ：Created in 2019/8/4 15:43
 */

namespace app\api\controller;

use app\api\service\DrugService;
use app\api\Utils\ReturnUtils;
use app\api\model\Drug as DrugModel;

class DrugController extends BaseController
{
    public function kindlist(){

        return ReturnUtils::TrueResult(DrugService::KindList());
    }

    public function add($name,$part,$guige,$yongliang,$build,$has,$price,$pay_ff,$is_show,$shuoming,$imgs,$kinds,$pharmacys,$father_pharmacy){
        return ReturnUtils::TrueResult(DrugService::add($name,$part,$guige,$yongliang,$build,$has,$price,$pay_ff,$is_show,$shuoming,$imgs,$kinds,$pharmacys,$father_pharmacy));
    }

    public function select($father_pharmacy){
        return ReturnUtils::TrueResult(DrugService::select($father_pharmacy));
    }

    public function update($id,$name,$part,$guige,$yongliang,$build,$has,$price,$pay_ff,$is_show,$shuoming,$imgs,$kinds,$pharmacys,$father_pharmacy){
        return ReturnUtils::TrueResult(DrugService::update($id,$name,$part,$guige,$yongliang,$build,$has,$price,$pay_ff,$is_show,$shuoming,$imgs,$kinds,$pharmacys,$father_pharmacy));
    }

    public function has($id,$has){
        DrugModel::update(['has' => $has],['id' => $id]);

        return ReturnUtils::TrueResult(null);
    }

    public function show($id){
        $drug = DrugModel::where(['id' => $id])->find();

        if($drug['is_show'] == 1){
            DrugModel::update(['is_show' => 0],['id' => $id]);
        }
        else{
            DrugModel::update(['is_show' => 1],['id' => $id]);
        }

        return ReturnUtils::TrueResult(null);
    }

}